//
//  MCRechargeHeaderView.m
//  TLYL
//
//  Created by MC on 2017/6/13.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCRechargeHeaderView.h"
@interface MCRechargeHeaderView ()
/*
 * 会员名称
 */
@property (nonatomic,strong)UILabel *lab_name;

/*
 * 账户金额
 */
@property (nonatomic,strong)UILabel *lab_money;

/*
 * 分隔线
 */
@property (nonatomic,strong)UIView * view_line;

@end

@implementation MCRechargeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    self.backgroundColor=[UIColor whiteColor];

    _lab_name = [[UILabel alloc]init];
    _lab_name.layer.cornerRadius=5;
    _lab_name.backgroundColor = [UIColor clearColor];
    _lab_name.layer.masksToBounds = YES;
    _lab_name.font = [UIFont systemFontOfSize:15];
    _lab_name.numberOfLines=1;
    _lab_name.text = @"尊敬的会员：Kaka";
    _lab_name.textAlignment=NSTextAlignmentLeft;
    [self addSubview:_lab_name];

    _lab_money = [[UILabel alloc]init];
    _lab_money.layer.cornerRadius=5;
    _lab_money.backgroundColor = [UIColor clearColor];
    _lab_money.layer.masksToBounds = YES;
    _lab_money.font = [UIFont systemFontOfSize:15];
    _lab_money.numberOfLines=1;
    _lab_money.text = @"您的账户余额：99999元";
    _lab_money.textAlignment=NSTextAlignmentLeft;
    [self addSubview:_lab_money];
    
    
    _view_line=[[UIView alloc]init];
    _view_line.backgroundColor=[UIColor grayColor];
    [self addSubview:_view_line];
    
    [self layOutConstraints];
    
    
}


-(void)layOutConstraints{
    
    [_lab_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    [_lab_money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(_lab_name.mas_bottom).offset(0);
        make.height.mas_equalTo(20);
    }];
    
    [_view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.height.mas_equalTo(1);
    }];
    
    
}

+(CGFloat)computeHeight:(id)info{
    return 60;
}

-(void)setDataSource:(id)dataSource{
    _dataSource=dataSource;
    NSString *str_name =@"尊敬的会员：Kaka";
    NSString *Left_name =@"尊敬的会员：";
    NSString *str_money=@"您的账户余额：99999元";
    NSString *Left_money=@"您的账户余额：";
    
    
    /*
     * 设置会员 富文本
     */
    NSRange range_name = [str_name rangeOfString:Left_name];
    [self setTextColor:_lab_name FontNumber:[UIFont systemFontOfSize:14] AndRange:range_name AndColor:[UIColor redColor]];
    
    /*
     * 设置账户余额 富文本
     */
    NSRange range_money = [str_money rangeOfString:Left_money];
    [self setTextColor:_lab_money FontNumber:[UIFont systemFontOfSize:14] AndRange:range_money AndColor:[UIColor redColor]];

}
//设置不同字体颜色
-(void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    label.attributedText = str;
}

@end




























